﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.OData.Query;

namespace Devonline.Identity.Admin.Controllers;

/// <summary>
/// 基础数据管理
/// </summary>    
[Route("api/[controller]")]
[ApiController]
[SecurityHeaders]
[Authorize(Roles = GROUP_MAINTAINERS)]
public class ParametersController : ControllerBase
{
    private readonly IDataService<IdentityDbContext, Parameter> _dataService;

    public ParametersController(IDataService<IdentityDbContext, Parameter> dataService) => _dataService = dataService;

    /// <summary>
    /// 查询数据管理
    /// </summary>
    /// <returns></returns>
    [HttpGet, EnableQuery]
    public IActionResult Get() => Ok(_dataService.GetQueryable());

    /// <summary>
    /// 创建数据管理
    /// </summary>
    /// <param name="entitySet"></param>
    /// <returns></returns>
    [HttpPost]
    public async Task<IActionResult> CreateAsync(ParameterViewModel entitySet) => Ok(await _dataService.AddAsync(entitySet));
    /// <summary>
    /// 创建数据管理
    /// </summary>
    /// <param name="entitySet"></param>
    /// <returns></returns>
    [HttpPut]
    public async Task<IActionResult> UpdateAsync(ParameterViewModel entitySet) => Ok(await _dataService.UpdateAsync(entitySet));
    /// <summary>
    /// 删除数据管理
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    [HttpDelete("{id}")]
    public async Task<IActionResult> DeleteAsync(string id)
    {
        await _dataService.DeleteAsync(id);
        return Ok();
    }
}